# -*- coding:utf-8 -*-
"""
Created on 1 jul 2011

@author: Olof Manbo
"""
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.2')
import pages
import logging

import diagram
import svgmap


application = webapp.WSGIApplication([
                                     ('/', pages.Main),
                                     ('/putfarms', pages.PutFarms),
                                     ('/putcourt', pages.PutCourt),
                                     ('/diagram', diagram.Page),
                                     ('/requestmap', diagram.RequestMap),
                                     ('/getnexttick', diagram.GetNextTick),
                                     ('/getresourcenamesandcss', diagram.GetResourceNamesAndCss),
                                     #('/getsvgmap', diagram.GetSvgMap),
                                     ('/svgmap', svgmap.Page),
                                     ('/channelready', diagram.ChannelReady),
                                     ],
                                     debug=True)

def profile_main():
    # This is the main function for profiling
    # We've renamed our original main() above to real_main()
    import cProfile, pstats, StringIO
    prof = cProfile.Profile()
    prof = prof.runctx("real_main()", globals(), locals())
    stream = StringIO.StringIO()
    stats = pstats.Stats(prof, stream=stream)
    stats.sort_stats("time")  # Or cumulative
    stats.print_stats(80)  # 80 = how many to print
    # The rest is optional.
    # stats.print_callees()
    # stats.print_callers()
    logging.info("Profile data:\n%s", stream.getvalue())

def real_main():
    run_wsgi_app(application)

if __name__ == "__main__":
    real_main()